package com.zmn.oms.common.enums;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import lombok.Getter;

import java.util.Objects;

/**
 * @ClassName RefundInitiateTypeEnum
 * @description: 发起退款类型枚举类
 * @author: wangyanci
 * @create: 2022-04-14 14:49
 * @Version 1.0
 **/
@Getter
public enum RefundInitiateTypeEnum {

    /**
     * 退款单退款
     */
    REFUND_ORDER(1),

    /**
     * 重复支付退款
     */
    REFUND_DUPLICATE(2),

    /**
     * 原单退差额
     */
    REFUND_DIFFERENCE(3),

    /**
     * 取消退款
     */
    CANCEL_REFUND(4),
    ;

    private Integer type;

    RefundInitiateTypeEnum(Integer type) {
        this.type = type;
    }

    public static String getRefundNoticeMqTag(Integer type) {
        if (NumberUtil.isNullOrZero(type)) {
            return null;
        }

        RefundInitiateTypeEnum refundInitiateTypeEnum = getRefundInitiateTypeEnum(type);
        if (Objects.isNull(refundInitiateTypeEnum)) {
            return null;
        }

        switch (refundInitiateTypeEnum) {
            case REFUND_ORDER:
            case CANCEL_REFUND:
                return MessageQueueTagConsts.OMS_ORDER_REFUND;
            case REFUND_DUPLICATE:
                return MessageQueueTagConsts.OMS_ORDER_DUPLICATE_PAY_REFUND;
            case REFUND_DIFFERENCE:
                return MessageQueueTagConsts.OMS_ORDER_DIFFERENCE_REFUND;
        }

        return null;
    }

    private static RefundInitiateTypeEnum getRefundInitiateTypeEnum(Integer type){
        if (NumberUtil.isNullOrZero(type)) {
            return null;
        }
        for (RefundInitiateTypeEnum value : RefundInitiateTypeEnum.values()) {
            if (Objects.equals(value.getType(), type)) {
                return value;
            }
        }

        return null;
    }

}
